package com.guoheng.hazard.sys.service.impl.hazard;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.guoheng.hazard.common.base.Result;
import com.guoheng.hazard.common.enums.ReviewStatusEnum;
import com.guoheng.hazard.sys.mapper.hazard.MajorHazardExamineMapper;
import com.guoheng.hazard.sys.model.dto.entpr.DealExaminationDTO;
import com.guoheng.hazard.sys.model.dto.hazard.CommitMajorHazardExamineDTO;
import com.guoheng.hazard.sys.model.dto.hazard.MajorHazardExamineSelectDTO;
import com.guoheng.hazard.sys.model.entity.hazard.MajorHazardExamine;
import com.guoheng.hazard.sys.service.hazard.MajorHazardExamineService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * 类功能描述:　MajorHazardExamineServiceImpl
 *
 * @author fbl
 * @date 2019-54-15 15:54
 */
@Service
public class MajorHazardExamineServiceImpl implements MajorHazardExamineService {

    @Resource
    private MajorHazardExamineMapper majorHazardExamineMapper;

    @Override
    public Result getHazardExamine(String entprName,Integer reviewStatus,Long entprId, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<MajorHazardExamineSelectDTO> hazardInfo = majorHazardExamineMapper.getHazardExamine(entprName,entprId,reviewStatus);
        PageInfo<MajorHazardExamineSelectDTO> majorHazardExaminePageInfo = new PageInfo<>(hazardInfo);
        return Result.success(majorHazardExaminePageInfo);
    }

    @Override
    public Result commitHazardExamine(CommitMajorHazardExamineDTO commitMajorHazardExamineDTO) {
        MajorHazardExamine majorHazardExamine = new MajorHazardExamine();
        BeanUtils.copyProperties(majorHazardExamine,commitMajorHazardExamineDTO);
        majorHazardExamine.setApplicationTime(new Date());
        majorHazardExamine.setReviewStatus(ReviewStatusEnum.REVIEW_STATUS_1.getCode());
        majorHazardExamineMapper.insertSelective(majorHazardExamine);
        return Result.success();
    }

    @Override
    public Result dealHazardExamine(Long id, DealExaminationDTO dealExaminationDTO) {
        MajorHazardExamine majorHazardExamine = new MajorHazardExamine();
        BeanUtils.copyProperties(dealExaminationDTO,majorHazardExamine);
        majorHazardExamine.setId(id);
        majorHazardExamineMapper.updateByPrimaryKeySelective(majorHazardExamine);
        return Result.success();
    }

    @Override
    public Result getHazardExamineDetail(Long id) {
        MajorHazardExamineSelectDTO majorHazardExamineSelectDTO = majorHazardExamineMapper.getHazardExamineDetail(id);
        return Result.success(majorHazardExamineSelectDTO);
    }


}
